FROM alpine:3.11.13 AS builder
RUN sed -i "s@dl-cdn.alpinelinux.org@mirrors.aliyun.com@g" /etc/apk/repositories \
#build-tools
&& apk --update add --no-cache gcc g++ make cmake wget git \
#mbtilesSrv osrm-backend
boost-dev \
#osrm-backend
bzip2-dev lua5.3-dev expat-dev zlib-dev \
#mapserver
gdal-dev proj-dev fcgi-dev cairo-dev harfbuzz-dev fribidi-dev protobuf-c-dev jpeg-dev giflib-dev geos-dev libxml2-dev postgresql-dev \
#daemon
perl \
#mapcache
apr-util-dev sqlite-dev curl-dev
RUN cd /tmp \
&& wget -c http://deb.debian.org/debian/pool/main/o/onetbb/onetbb_2021.11.0.orig.tar.xz \
&& tar xf onetbb_2021.11.0.orig.tar.xz \
&& cmake -DCMAKE_BUILD_TYPE:STRING=Release -Bb -DTBB_TEST:BOOL=OFF oneTBB-2021.11.0 \
&& cmake --build b -t install \
&& rm -rf b oneTBB-2021.11.0 onetbb_2021.11.0.orig.tar.xz

RUN cd /tmp \
&& git clone https://github.com/Project-OSRM/osrm-backend.git \
&& cd osrm-backend \
&& git checkout v5.27.1 \
&& cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_CXX_FLAGS:STRING="-Wno-error -Wno-error=array-bounds" -DCMAKE_C_FLAGS:STRING="-Wno-error -Wno-error=array-bounds" -DTBB_INCLUDE_DIR:PATH=/usr/local/include -Bb . \
&& cmake --build b -t install \
&& cd .. \
&& rm -rf osrm-backend

RUN cd /tmp \
&& git clone https://gitee.com/zjp369/mbtiles-srv.git \
&& cmake -DCMAKE_BUILD_TYPE:STRING=Release -Bb mbtiles-srv \
&& cmake --build b -t install \
&& rm -rf b mbtiles-srv

RUN cd /tmp \
&& wget -c https://download.osgeo.org/mapserver/mapserver-7.6.5.tar.gz \
&& tar xf mapserver-7.6.5.tar.gz \
&& cmake -DCMAKE_BUILD_TYPE:STRING=Release -Bb mapserver-7.6.5 \
&& cmake --build b -t install \
&& rm -rf b mapserver-7.6.5

RUN cd /tmp \
&& wget -c http://archive.ubuntu.com/ubuntu/pool/universe/d/daemon/daemon_0.6.4.orig.tar.gz \
&& tar xf daemon_0.6.4.orig.tar.gz \
&& cd daemon-0.6.4 \
&& ./configure \
&& sed -i 's/CEOF/VEOF/g' daemon.c \
&& make \
&& make install \
&& cd .. \
&& rm -rf daemon-0.6.4 daemon_0.6.4.orig.tar.gz

RUN cd /tmp \
&& git clone https://github.com/MapServer/mapcache.git \
&& cmake -DCMAKE_BUILD_TYPE:STRING=Release -DWITH_APACHE:BOOL=OFF -Bb mapcache \
&& cmake --build b -t install \
&& rm -rf b mapcache

RUN cp -r /usr/local/lib64/* /usr/local/lib/ \
&& cd /usr/local/lib \
&& rm -rf cmake pkgconfig *.a /usr/local/include /usr/local/lib64


FROM alpine:3.11.13
RUN sed -i "s@dl-cdn.alpinelinux.org@mirrors.aliyun.com@g" /etc/apk/repositories \
&& apk --update add --no-cache \
#http(forward) htpasswd
nginx apr-util \
#mbtilesSrv
boost-serialization boost-system boost-date_time \
#osrm-backend
bzip2 lua5.3 expat zlib \
#osrm-backend boost
boost-iostreams boost-filesystem boost-program_options boost-thread boost-chrono libstdc++ icu-libs libffi gdbm ncurses-terminfo-base ncurses-libs readline sqlite-libs \
#mapserver
gdal proj fcgi cairo harfbuzz fribidi protobuf-c jpeg giflib geos libxml2 postgresql \
#nginx -> mapserver
spawn-fcgi \
#mapcache
apr-util sqlite curl \
&& mkdir -p /run/nginx
ADD files.tar.gz /
COPY --from=builder /usr/local /usr/local
EXPOSE 3000
